import {
  Inject,
  Controller,
  Get,
  Post,
  Query,
  Body,
} from '@midwayjs/decorator';
import { Context } from '@midwayjs/koa';
import { ApplyFriendDTO } from '../dto/friend';
import { FriendService } from '../service/friend.service';

@Controller('/api')
export class FriendController {
  @Inject()
  ctx: Context;

  @Inject()
  friendService: FriendService;

  /**
   * 申请添加好友
   */
  @Post('/applyFriend')
  async applyFriend(@Body() applyFriend: ApplyFriendDTO): Promise<any> {
    const result = await this.friendService.applyFriend(applyFriend);
    return result;
  }

  /**
   * 获取好友申请列表
   */
  @Get('/getFriendApplyList')
  async getFriendApplyList(): Promise<any> {
    const result = await this.friendService.getFriendApplyList();
    return result;
  }

  /**
   * 更新好友状态
   * params:{
   *  status:'', 1 同意好友申请 2 申请添加好友 3 拒绝添加好友
   * }
   */
  @Post('/updateFriendStatus')
  async updateFriendStatus(@Body() params: ApplyFriendDTO): Promise<any> {
    const result = await this.friendService.updateFriendStatus(params);
    return result;
  }

  /**
   * 获取好友列表
   */
  @Get('/getFriendList')
  async getFriendList(): Promise<any> {
    const result = await this.friendService.getFriendList();
    return result;
  }

  /**
   * 获取好友详情
   */
  @Get('/getFriendDetails')
  async getFriendDetails(@Query('id') id: number): Promise<any> {
    const result = await this.friendService.login(id);
    return result;
  }

  /**
   * 删除好友
   */
  @Post('/deleteFriend')
  async deleteFriend(@Body('id') id: number): Promise<any> {
    const result = await this.friendService.deleteFriend(id);
    return result;
  }
}
